package 序列;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    static int N = 2010, m, n;
    static int[] a = new int[N];
    static int[] b = new int[N];
    static int[] c = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        while (T-- > 0) {
            m = in.nextInt();
            n = in.nextInt();
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a, 0, n);
            for (int i = 0; i < m - 1; i++) {
                for (int j = 0; j < n; j++) {
                    b[j] = in.nextInt();
                }
                merge();
            }
            for (int i = 0; i < n; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }
    }

    private static void merge() {
        PriorityQueue<PII> heap = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            heap.offer(new PII(b[i] + a[0], 0));
        }
        for (int i = 0; i < n; i++) {
            PII t = heap.poll();
            c[i] = t.x;
            heap.offer(new PII(t.x - a[t.y] + a[t.y + 1], t.y + 1));
        }
        a = c.clone();
    }
}

class PII implements Comparable<PII> {
    int x, y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public int compareTo(PII o) {
        return this.x - o.x;
    }
}